<?php
/**
 * @author sql
 * 通讯录打标签
 */

namespace App\Http\Controllers\Owner;

use App\Models\DriverLable;
use App\Models\VLable;
use Illuminate\Http\Request;
use App\Http\Controllers\Owner\BaseController;

class DriverLabelController extends BaseController
{
    /**
     * 选择司机通讯录里的id号，进行新增标签，并绑定
     * 1.查看标签是否已经存在，存在了，不允许重复创建
     * 2.不存在，创建新标签
     * 3.将司机的信息与新标签绑定
     */
    public function store(Request $request)
    {
        $lable_name = $request->post('lable_name');
        $ids = $request->post('ids');
        $vmodel = new VLable();
        $lableInfo = $vmodel->getInfoByLableName($lable_name);
        if ($lableInfo) {
            return $this->error('标签名:【' . $lable_name . '】已存在');
        }
        //建标签
        $lable_id = $vmodel->add($lable_name);
        //将司机的信息与新标签绑定
        $driverLable = new DriverLable();

        $driverLable->store($ids, $lable_name, $lable_id, $this->owner_id, $this->uuid);
        return $this->success('保存成功');

    }
}
